package student.aistar.layOrder.producer;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
import student.aistar.layOrder.enums.DelayTypeEnum;

import javax.annotation.Resource;
import javax.annotation.Resources;

import static student.aistar.config.RabbitMQConfig.*;

/**
 * 本类用来演示: 生产者生产消息 -> 通过交换机 -> 把消息分发给指定延迟队列
 *
 * @author: qinFeng
 * @date: 2021/10/28 13:40
 */
@Component
public class DelayMessageProducer {
    @Resource
    private RabbitTemplate rabbitmqTemplate;

    public void send(String message, DelayTypeEnum type){
        switch (type){
            case DELAY_10s:
                rabbitmqTemplate.convertAndSend(DELAY_EXCHANGE_NAME, DELAY_QUEUE_A_ROUTING_KEY, message);
                break;
            case DELAY_60s:
                rabbitmqTemplate.convertAndSend(DELAY_EXCHANGE_NAME, DELAY_QUEUE_B_ROUTING_KEY, message);
                break;
            default:

        }
    }
}
